<template>
  <tl-sub-page :render="render" :visible.sync="visible" v-dialogDrag :title="moduleTitle" :close-on-click-modal="false" class="tl-dialog" width="800px" @open="open" @close="close">
    <el-row>
      <el-col :span="24">
        <el-button type="danger" style="float: right" size="small" icon="el-icon-close" circle @click="doCancelEdit"></el-button>
      </el-col>
    </el-row>
    <br>
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" disabled>
      <el-row>
        <el-col :span="12">
          <el-form-item label="任务名称" prop="taskname">
            <el-input v-model="model.taskname" type="text"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目名称" prop="projectname">
            <el-input v-model="model.projectname" type="text"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="任务内容" prop="taskdetail">
            <el-input v-model="model.taskdetail" type="textarea" maxlength="1000" show-word-limit :autosize="{ minRows:1, maxRows:3 }" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="model.customerattach">
        <el-col :span="24">
          <el-form-item label="客户接触现状" prop="customerattach" >
            <el-input v-model="model.customerattach" type="textarea" maxlength="1000" show-word-limit :autosize="{ minRows:1, maxRows:3 }" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="model.improveplan">
        <el-col :span="24">
          <el-form-item label="客户关系改善计划" prop="improveplan">
            <el-input v-model="model.improveplan" type="textarea" maxlength="1000" show-word-limit :autosize="{ minRows:1, maxRows:3 }" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="关闭原因" prop="closereason">
            <el-input v-model="model.closereason" type="textarea" :rows="4" maxlength="1000">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="申请人姓名" prop="username">
            <el-input v-model="model.username"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请人工号" prop="usercode">
            <el-input v-model="model.usercode"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <tl-approval-history ref="history" sourceType="MpmProjectTaskClose" :sourceId="model.id" />
    <div slot="footer" class="dialog-footer">
      <tl-attachment sourceType="MpmProjectTaskClose" :sourceId="model.id" disabled :editable="stateEdit"></tl-attachment>
      <el-button type="primary" @click="$refs.history.visible = true">
        <svg-icon icon-class="list" />审批历史
      </el-button>
    </div>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: {},
  data() {
    return {
      moduleTitle: '任务关闭审批',
      urlPrefix: '/mpm/projectTaskClose/',
      url: {
        // 额外的url
        queryCodeList: '/mpm/projectTask/dataCodeList',
        queryProject: '/mpm/project/list',
        queryTaskInfo: '/mpm/projectTask/list'
      }
    }
  },
  methods: {
    doCancelEdit() {
      this.visible = false
      this.$emit('close')
      this.$emit('refresh')
    },
    async loaded() {
      // 查询任务信息
      getAction(this.url.queryTaskInfo, { qry_taskid: this.model.taskid }).then((res) => {
        if (res.success && res.result.dataList.length > 0) {
          this.$set(this.model, 'taskdetail', res.result.dataList[0].taskdetail)
          this.$set(this.model, 'customerattach', res.result.dataList[0].customerattach)
          this.$set(this.model, 'improveplan', res.result.dataList[0].improveplan)
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
      // 查询项目
      await getAction(this.url.queryProject, { qry_projectcode: this.model.projectcode }).then((res) => {
        if (res.success && res.result.dataList.length > 0) {
          this.$set(this.model, 'projectname', res.result.dataList[0].projectname)
        } else {
          this.$tap.alert(res.message, 'warning')
        }
      })
      .catch((err) => {
        this.$tap.alert(err.message, 'warning')
      })
    }
  }
}
</script>

